﻿Imports System
Imports System.Text
Imports System.Collections.Generic
Imports Microsoft.VisualStudio.TestTools.UnitTesting
Imports System.Xml.Serialization
Imports System.IO
Imports Microsoft.VisualStudio.TestTools.Common
Imports System.Xml
Imports System.Collections

<TestClass()> Public Class LendoTRX

    Private testContextInstance As TestContext

    '''<summary>
    '''Gets or sets the test context which provides
    '''information about and functionality for the current test run.
    '''</summary>
    Public Property TestContext() As TestContext
        Get
            Return testContextInstance
        End Get
        Set(ByVal value As TestContext)
            testContextInstance = value
        End Set
    End Property

#Region "Additional test attributes"
    '
    ' You can use the following additional attributes as you write your tests:
    '
    ' Use ClassInitialize to run code before running the first test in the class
    ' <ClassInitialize()> Public Shared Sub MyClassInitialize(ByVal testContext As TestContext)
    ' End Sub
    '
    ' Use ClassCleanup to run code after all tests in a class have run
    ' <ClassCleanup()> Public Shared Sub MyClassCleanup()
    ' End Sub
    '
    ' Use TestInitialize to run code before running each test
    ' <TestInitialize()> Public Sub MyTestInitialize()
    ' End Sub
    '
    ' Use TestCleanup to run code after each test has run
    ' <TestCleanup()> Public Sub MyTestCleanup()
    ' End Sub
    '
#End Region

    <TestMethod()> Public Sub Lendo_TodosValores_Conteudo_XML_Do_TRX()

        Dim _arquivo As String = Global.FrameworkTeste.LocaisEmDisco.StorageRaiz & "TRXTeste\" & "Teste.trx"
        Dim reader As XmlTextReader = New XmlTextReader(_arquivo)
        Dim elementos As ArrayList = New ArrayList

        Do While (reader.Read())
            Select Case reader.NodeType
                Case XmlNodeType.Element
                    If reader.HasAttributes Then 'Se existirem atributos
                        While reader.MoveToNextAttribute()
                            'Pega o valor do atributo.
                            elementos.Add(reader.Value)
                        End While
                    End If
                Case XmlNodeType.Text
                    'Incluir o texto do elemento no ArrayList
                    elementos.Add(reader.Value)
            End Select
        Loop

        'Dim num As String
        'For Each num In elementos
        '    Console.WriteLine(num)
        'Next

        Assert.IsTrue(True)

    End Sub

    <TestMethod()> Public Sub Lendo_TodosNames_Conteudo_XML_Do_TRX()

        Dim _arquivo As String = Global.FrameworkTeste.LocaisEmDisco.StorageRaiz & "TRXTeste\" & "Teste.trx"
        Dim reader As XmlTextReader = New XmlTextReader(_arquivo)
        Dim elementos As ArrayList = New ArrayList

        Do While (reader.Read())
            Select Case reader.NodeType
                Case XmlNodeType.Element
                    Console.WriteLine(reader.LocalName)
                    If reader.HasAttributes Then 'Se existirem atributos
                        While reader.MoveToNextAttribute()
                            'Pega o valor do atributo.

                            Dim _node As String = String.Format("Name {0}, Prefix: {1}, LocalName: {2}", reader.Name, reader.Prefix, reader.LocalName)
                            'elementos.Add(reader.Name)
                            elementos.Add(_node)
                        End While
                    End If
                Case XmlNodeType.Text
                    'Incluir o texto do elemento no ArrayList
                    'elementos.Add(reader.Name)
            End Select
        Loop
        Console.WriteLine("---------")
        Dim num As String
        For Each num In elementos
            Console.WriteLine(num)
        Next

        Assert.IsTrue(True)


    End Sub

    <TestMethod()> Public Sub Lendo_Secao_UnitTestResult_Do_TRX()

        Dim _arquivo As String = Global.FrameworkTeste.LocaisEmDisco.StorageRaiz & "TRXTeste\" & "Teste.trx"
        Dim reader As XmlTextReader = New XmlTextReader(_arquivo)
        Dim elementos As ArrayList = New ArrayList

        Do While (reader.Read())
            Select Case reader.NodeType
                Case XmlNodeType.Element
                    If reader.LocalName = "UnitTestResult" Then
                        Dim _filtro As String = String.Format("UnitTestResult: {0}, outcome: {1}. {2}", reader.Item("testName"), reader.Item("outcome"), reader.Item("duration"))
                        elementos.Add(_filtro)
                    End If
            End Select
        Loop
        Console.WriteLine("---------")
        Dim num As String
        For Each num In elementos
            Console.WriteLine(num)
        Next


        Assert.IsTrue(True)

    End Sub

    <TestMethod()> Public Sub Obtendo_A_Duracao_De_Um_Teste_Executado_TRX()

        Dim _arquivo As String = Global.FrameworkTeste.LocaisEmDisco.StorageRaiz & "TRXTeste\" & "Teste.trx"
        Dim reader As XmlTextReader = New XmlTextReader(_arquivo)
        Dim elementos As ArrayList = New ArrayList

        Do While (reader.Read())
            Select Case reader.NodeType
                Case XmlNodeType.Element
                    If reader.LocalName = "UnitTestResult" Then
                        Dim _filtro As String = String.Format("Test={0} Resultado={1} Duration={2}", reader.Item("testName"), reader.Item("outcome"), reader.Item("duration"))
                        elementos.Add(_filtro)
                    End If
            End Select
        Loop
        Console.WriteLine("---------")
        Dim num As String
        For Each num In elementos
            Console.WriteLine(num)
        Next


        Assert.IsTrue(True)

    End Sub


    <TestMethod()> Public Sub Lendo_E_Gerando_Relatorio_Com_UnitTestResult_Do_TRX()

        Dim _arquivo As String = Global.FrameworkTeste.LocaisEmDisco.StorageRaiz & "TRXTeste\" & "Teste.trx"
        Dim reader As XmlTextReader = New XmlTextReader(_arquivo)
        Dim elementos As ArrayList = New ArrayList

        Do While (reader.Read())
            Select Case reader.NodeType
                Case XmlNodeType.Element
                    If reader.LocalName = "UnitTestResult" Then
                        Dim _filtro As String = String.Format("<td>{0}.jpg</td><td>{1}</td><td>{2}</td>", reader.Item("outcome"), reader.Item("testName"), reader.Item("duration"))
                        elementos.Add(_filtro)
                    End If
            End Select
        Loop
        Console.WriteLine("<table>")
        Console.WriteLine("<tr>")
        Console.WriteLine("<td>Status</td><td>Teste</td><td>Duração</td>")
        Console.WriteLine("</tr>")
        Dim num As String
        For Each num In elementos
            Console.WriteLine("<tr>")
            Console.WriteLine(num)
            Console.WriteLine("</tr>")
        Next
        Console.WriteLine("</table>")

        Assert.IsTrue(True)

    End Sub

End Class





Public Class AClasse

    

End Class